
#ifndef _DEBUG_H_
#define _DEBUG_H_	1

#include <time.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>

#if defined(__cplusplus)
extern "C" {
#endif

#define DEBUG_SHOW_DEBUG	1

#define DEBUG_NONE		0
#define DEBUG_EMERG		1
#define DEBUG_ALERT 	 	2
#define DEBUG_CRIT		3
#define DEBUG_ERROR		4
#define DEBUG_WARNING		5
#define DEBUG_NOTICE		6
#define DEBUG_INFO		7
#define DEBUG_DEBUG		8
#define DEBUG_VERBOSE		9
#define DEBUG_MIN		DEBUG_NONE
#define DEBUG_MAX		DEBUG_VERBOSE

/* Define used colors */
#define DEBUG_COLOR_BLACK			0
#define DEBUG_COLOR_RED				1
#define DEBUG_COLOR_GREEN			2
#define DEBUG_COLOR_MAGENTA			3
#define DEBUG_COLOR_BLUE			4
#define DEBUG_COLOR_PINK			5
#define DEBUG_COLOR_CYAN			6
#define DEBUG_COLOR_WHITE			7
#define DEBUG_COLOR_NONE			8
#define DEBUG_COLOR_DEFAULT			8

#ifdef DEBUG_SHOW_DEBUG
	#define d_message(format, arg...) 	__d_debug( DEBUG_NONE,		__FUNCTION__, __LINE__, format, ##arg )
	#define d_fatal(format, arg...) 	__d_debug( DEBUG_CRIT,		__FUNCTION__, __LINE__, format, ##arg )
	#define d_error(format, arg...) 	__d_debug( DEBUG_ERROR,		__FUNCTION__, __LINE__, format, ##arg )
	#define d_warning(format, arg...)	__d_debug( DEBUG_WARNING,	__FUNCTION__, __LINE__, format, ##arg )
	#define d_notice(format, arg...)	__d_debug( DEBUG_NOTICE,	__FUNCTION__, __LINE__, format, ##arg )
	#define d_info(format, arg...) 		__d_debug( DEBUG_INFO,		__FUNCTION__, __LINE__, format, ##arg )
	#define d_debug(format, arg...)		__d_debug( DEBUG_DEBUG,		__FUNCTION__, __LINE__, format, ##arg )
	#define d_verbose(format, arg...)	__d_debug( DEBUG_VERBOSE,	__FUNCTION__, __LINE__, format, ##arg )
#else
	#define d_message(format, arg...)	do {} while (0)
	#define d_fatal(format, arg...)		do {} while (0)
	#define d_error(format, arg...)		do {} while (0)
	#define d_warning(format, arg...)	do {} while (0)
	#define d_notice(format, arg...)	do {} while (0)
	#define d_info(format, arg...)		do {} while (0)
	#define d_debug(format, arg...)		do {} while (0)
	#define d_verbose(format, arg...)	do {} while (0)
#endif		//#ifdef DEBUG_SHOW_DEBUG

#ifndef FALSE
#define FALSE		0
#endif

#ifndef TRUE
#define TRUE		1
#endif

#ifndef false
#define false		0
#endif

#ifndef true
#define true		1
#endif


#ifndef d_MAX
#define d_MAX(x,y)	((x)>(y)?(x):(y))
#endif

#ifndef d_MIN
#define d_MIN(x,y)	((x)<(y)?(x):(y))
#endif

/* debug.c */
extern void d_debug_bin_buffer(const unsigned char *data, int len, const char *from);
extern void d_init_debug(char *magic, int level, int log, int fg, int bg);
extern int d_print_able(int level);
extern int d_get_debug_level();
extern int d_set_debug_level(int level);
extern int d_get_log_level();
extern int d_set_log_level(int level);
extern void d_destroy_debug();
void __d_debug(int level, const char *filename, const int linenum, char *format, ...);

#if defined(__cplusplus)
}
#endif

#endif		// #ifndef _DEBUG_H_
